<style scoped src="./index.scss" lang="scss" rel="stylesheet/scss"></style>
<template src="./index.html"></template>
<script>
    import WxwebMenu from "components/WxwebMenu/index";
    export default {
        mixins: [Vue.prototype.$vFN.Mixins.Base, Vue.prototype.$vFN.Mixins.Edit],
        components: {
            WxwebMenu,
        },
        data() {
            return {
                appWindow: window,
                boxVisible: false,
                form: {
                    // 是否微信生效 0否 1是
                    isOpen: 0,
                    // 菜单组名称
                    name: "",
                    // 菜单类型 1默认 2个性化
                    menuType: 1,
                    // 自定义菜单
                },
                menuLst: [],

                // 页面接口地址
                apiUrl: {
                    create: "mall-site-portal/wechat-mp-menu-group/create",
                    update: "mall-site-portal/wechat-mp-menu-group/update",
                    detail: "mall-site-portal/wechat-mp-menu-group/getItem",
                },
            };
        },
        methods: {
            // 初始化
            async init() {

                // 初始化数据
                await this.mixinEdit_editBoxInit({
                    model: "form",
                    id: this.id,
                })

            },


            // 编辑修改的参数扩展方法
            mixinEdit_editDataExtend(data_) {

                // 添加
                if (this.mixinEdit_editType == "add") {}
                // 修改
                else if (this.mixinEdit_editType == "update") {

                    let _list = []
                    data_.menuLst.forEach((item, index) => {

                        let _d = this.toItemData(item);
                        _d.subMenuLst = []
                        if (!this.$vFN.Utils.isEmpty(item.subMenuLst)) {

                            item.subMenuLst.forEach((iitem, index) => {
                                _d.subMenuLst.push(this.toItemData(iitem))
                            })
                        }
                        _list.push(_d)
                    })
                    console.error("_list",_list)
                   this.menuLst = _list

                }
                console.error(data_);
                return data_
            },

            toItemData(data_) {
                let _d = {
                    albumInfoId: data_.albumInfoId,
                    appid: data_.appid,
                    content: "",
                    msgType: data_.msgType,
                    name: data_.name,
                    pagepath: data_.pagepath,
                    type: data_.type,
                    url: data_.url,
                    _content:{
                        text: "",
                        image: null,
                        voice: null,
                        video: null,
                        news: null,
                        keyword: null,
                    },
                }


                if (data_.msgType == "text") {
                    _d._content.text = data_.content
                } else if (data_.msgType == "image") {
                    _d._content.image = data_.albumInfo
                } else if (data_.msgType == "video") {
                    _d._content.video = data_.albumInfo
                } else if (data_.msgType == "voice") {
                    _d._content.voice = data_.albumInfo
                } else if (data_.msgType == "news") {
                    _d._content.news = data_.albumInfo
                } else if (data_.msgType == "keyword") {
                    _d._content.keyword = data_.wechatMpReply
                }
                return _d
            },

            // form 提交添加/修改 的参数扩展方法 返回false 则不提交用于扩展验证
            mixinEdit_editFormSubmitExtend(data_) {
                data_.menuLst = this.$refs.wxwebMenuRef.getFormData();
                return data_
            },



        },
        mounted() {
            this.init();
        },
        activated() {},
    };
</script>
